package com.example.towSpringBoot.service.impl;


import com.example.towSpringBoot.common.PageQuery;
import com.example.towSpringBoot.common.PageResult;
import com.example.towSpringBoot.entity.Department;
import com.example.towSpringBoot.entity.Permission;
import com.example.towSpringBoot.mapper.PermissionMapper;
import com.example.towSpringBoot.service.PermissionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xinTong
 * @since 2024-01-24
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    /**
     * 查询全部数据
     * @return
     */
    @Override
    public List<Permission> listAll() {

        List<Permission> list = permissionMapper.listAll();
        return list;
    }

    /**
     * 分页查询数据
     * @param pageQuery
     * @return
     */
    @Override
    public PageResult list(int pageNum, int pageSize) {
        // 先设置PageHelper必要参数
        PageHelper.startPage(pageNum, pageSize);
        // TODO: 差一个高级查询
        Page<Permission> page = permissionMapper.list();

        // 将Page数据赋值到PageResult中，展示给前端
        PageResult pageResult = new PageResult();
        pageResult.setList(page);
        pageResult.setTotal(page.getTotal());
        pageResult.setPageNum(page.getPageNum());
        pageResult.setPageSize(page.getPageSize());

        return pageResult;
    }

    /**
     * 通过角色id获取相应的权限信息
     * @param roleId
     * @return
     */
    @Override
    public List<Permission> queryPermission(Long roleId) {
        List<Permission> list = permissionMapper.queryPermission(roleId);

        return  list;
    }
}
